Nekodb A tiny ODM for Nedb and Mongodb
The Ne comes from NeDB, and ko refers to the Japanese diminuitive “ko” (小) or little.
What is Nedb?
NeDB is a lightweight database written entirely in Javascript, and that implements the well-known and loved MongoDB API. It is packaged as a Node module that be used with a simple require and can be used as an in-memory only or persistent datastore. You can think of it as SQLite for MongoDB projects.
NekoDB comes with NeDB built in, so you can access a Mongo-like database, without actually installing or running a database at all. NeDB is suitable for datasets in the range of tens of thousands of documents. It is perfect for develop or small & medium websites. For larger datasets, it is recommended you upgrade to MongoDB.
- To build the simplest, easiest to use ODM
- Stay as close to MongoDB syntax as possible
- Provide model validation and model referencing
- Beyond that, just provide a thin wrapper over the native functionality
Support NeDB and MongoDB with an identical interface
- Promisify NeDB: no callback hell, only lovely Promises
- You can use it as
async await
in nodejs7.6 & more
Connecting and creating schemas
1 | const ko = require('nekodb') |
if you want to connect mongodb rather than nedb
1 | ko.connect({ |
or
1 | ko.connect({ |
Creating a model
1 | const celebrity = ko.models.Celebrity.create({ |
if you want to use async await instead of promise call:
1 | instance = await celebrity.save() |
Finding models
1 | ko.models.Celebrity.find({}).then(instances => { |
Updating a model
1 | ko.models.Celebrity.findOne({name: 'Kim Kardashian'}).then(instance => { |
Deleting models
1 | ko.models.Celebrity.deleteOne({name: 'Johnny Depp'}).then(deletedCount => { |
that’s it.
It has more features that you can see them on NEKDODB